Uec3.payInvoiceIndexWindow = Ext.extend(Ext.app.Module, {
    id: 'payInvoice_index',
    objsCollection:new Ext.util.MixedCollection(true),
    getObjByKey:function(key){
		return this.objsCollection.get(key);
	},
    delPayInvoice:function(id){
		var grid=this.getObjByKey("payInvoice_grid");
		Ext.Msg.confirm('信息','确定要删除',function(btn){
		 	if(btn=='yes'){
		 		grid.loadMask.show();
			  	Ext.Ajax.request({
			  	url:Uec3.App.Constants.homeUrl+'/payInvoice/base!delete.do',
			  	params:{'id':id},
        		success:function(response){
	        		var result=Ext.decode(response.responseText);
	        		if(result.success=='OK'){
	        			grid.getStore().reload();
	        		}else{
	        			Ext.Msg.alert('错误',result.success); 
	        		}
		        	grid.loadMask.hide();
        		},
        		failure:function(){
        			Ext.Msg.alert('网络问题');
        			grid.loadMask.hide();
        		}
        			
			  	});
		    }
		});
	},
	initialDetailView:function(id){
		var store=this.getObjByKey("store");
		var record=store.getById(id);
		var desktop =Uec3.App.getDesktop(); 
		desktop.launchWindowByParam("payInvoice_operation",{id:id,winId:id}); 
	}	,
   getPanel:function(params) {
   	var win=this;
		/*store*/
	var payInvoice_record=Ext.data.Record.create( [ 
		{
			name : 'id',
			type : 'int',
			mapping : 'id'
		}, {
			name : 'companyId',
			type : 'int',
			mapping : 'companyId'
		}, {
			name : 'customerId',
			type : 'int' 
		}, {
			name : 'code',
			type : 'string',
			mapping : 'code'
		}, {
			name : 'invoiceType',
			type : 'int',
			mapping : 'invoiceType'
		}, {
			name : 'invoiceTypeVarName',
			type : 'string',
			mapping : 'invoiceTypeVarName'
		}, {
			name : 'codeOfBuyer',
			type : 'string',
			mapping : 'codeOfBuyer'
		}, {
			name : 'codeOfSeller',
			type : 'string',
			mapping : 'codeOfSeller'
		},  {
			name : 'amount',
			type : 'double',
			mapping : 'amount'
		}, {
			name : 'status',
			type : 'int',
			mapping : 'status'
		}, {
			name : 'ActualPayer',
			type : 'int',
			mapping : 'ActualPayer'
		},{
			name : 'ActualPayerName',
			type : 'string',
			mapping : 'ActualPayerName'
		}, {
			name : 'gmtActualPay',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtActualPay'
		},{
			name : 'gmtActualPayName',
			type : 'string',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtActualPayName'
		}, {
			name : 'creator',
			type : 'int',
			mapping : 'creator'
		}, {
			name : 'creatorName',
			type : 'string',
			mapping : 'creatorName'
		},{
			name : 'gmtCreate',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtCreate'
		}, {
			name : 'payerName',
			type : 'string',
			mapping : 'payerName'
		},{
			name : 'gmtPay',
			type : 'date',
			dateFormat:'Y-m-d H:i:s',
			mapping : 'gmtPay'
		},{
			name : 'workFlowId',
			type : 'int',
			mapping : 'workFlowId'
		}, {
			name : 'currentorId',
			type : 'int',
			mapping : 'currentorId'
		}, {
			name : 'customerName',
			type : 'string',
			mapping : 'customerName'
		}, {
			name : 'documentTypeVarName',
			type : 'string',
			mapping : 'documentTypeVarName'
		}, {
			name : 'statusVarName',
			type : 'string',
			mapping : 'statusVarName'
		}]);
		var payInvoice_store=new Ext.data.Store( {
			proxy : new Ext.data.HttpProxy( {
				url : Uec3.App.Constants.homeUrl+'/payInvoice/base!extList.do'
			}),
			pruneModifiedRecords : true,
			paramNames : {
				start : "start",
				limit : "limit",
				sort : "sort",
				dir : "dir"
			},
			remoteSort:true,
			reader : new Ext.data.JsonReader( {
				totalProperty : 'totalProperty',
				root : 'root'
			}, payInvoice_record),
			listeners:{
			
			}
		});
		win.objsCollection.add("store",payInvoice_store);

	var payInvoice_cm = new Ext.grid.ColumnModel( [ 
		new Ext.grid.RowNumberer(), 
		{
		header : '操作',
		width : 75,
		renderer:getHtmlCode
		},
		{
		header : '单据号',
		width : 90,
		sortable : true,
		align:"right",
		dataIndex : 'codeOfBuyer'
		},
		{
		header : '供应商',
		width : 180,
		sortable : true,
		dataIndex : 'customerName'
		},
		{
		header : '状态',
		width : 75,
		sortable : true,
		dataIndex : 'statusVarName'
		},
		{
		header : '付款金额',
		width : 100,
		sortable : true,
		align:"right",
		dataIndex : 'amount',
		renderer:showMoney
		},
		{
		header : '收据类型',
		width : 90,
		sortable : true,
		dataIndex : 'invoiceTypeVarName'
		},
		{
		header : '建单人',
		width : 75,
		sortable : true,
		align:"left",
		dataIndex : 'creatorName'
		},
		{
		header : '建单日期',
		width : 90,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtCreate'
		},{
		header : '实际支付人',
		width : 75,
		sortable : true,
		align:"right",
		dataIndex : 'ActualPayerName'
		},
		{
		header : '实际支付日期',
		width : 90,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtActualPay'
		},
		{
		header : '支付人',
		width : 75,
		sortable : true,
		align:"right",
		dataIndex : 'payerName'
		},
		{
		header : '支付日期',
		width : 90,
		sortable : true,
		align:"right",
		renderer:Ext.util.Format.dateRenderer("Y-m-d"),
		dataIndex : 'gmtPay'
		}]);
				
	var payInvoice_grid=new Ext.grid.EditorGridPanel({
	    cm:payInvoice_cm,
	    viewConfig : {
				forceFit : true,
				getRowClass : function(record,rowIndex,rowParams,store){
					//禁用数据显示红色
					if(record.data.amount<0){
						return 'x-grid-record-red';
					}else{
						return '';
					}
					
				}
		},
		store : payInvoice_store,
		selModel : new Ext.grid.RowSelectionModel( {
			moveEditorOnEnter : true
		}),
		iconCls : 'icon-grid',
		loadMask : {
			msg : '数据加载中...'
		},
		stripeRows : true,
		autoScroll : true,
		//autoload : true,
		height : 300,
		width : '100%',
		bbar : new Ext.PagingToolbar({
			pageSize : 10,
			store : payInvoice_store,
			displayInfo : true,
			style : 'align:center',
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录"
		}),
		tbar : new Ext.Toolbar(['-', {
			text : '新增',
			iconCls : 'icon-add',
			handler : addNewWindow
		}])
	});
	this.objsCollection.add("payInvoice_grid",payInvoice_grid);
	function addNewWindow(){
		var desktop =Uec3.App.getDesktop();   
		desktop.launchWindowByParam("payInvoice_operation"); 
	}
	
	/* FormPanel */
	var payInvoice_formPanel = new Ext.FormPanel({
		labelAlign : 'right',
		frame : true,
		items : [{
				  height:60,
		          layout:'hbox',
		          border:false,
		          layoutConfig: 
		             {     
		               padding:'5',
					   align:'middle' 
                  },            
		          items:[			             
		             {
		               xtype:'label',
		               text:'浏览付款单',
		               style: {font:'bold 30px arial,serif'}
		             },{
                        xtype:'textfield',
                        style:"margin-left:20px;",
                        name:'keyWords'
                     },{
                        xtype:'button',
                        text:'查        找',
                        width:50,
                        margins:'0 10',
                        style:"margin-left:40px;",
                        handler:search
                     },{
				  		xtype:'label',
				  		text:'可查条件:单据号,供应商,支付状态',
				  		style:"color:#ff3333;font-size:14px;margin-left:40px;"
			 		 }]
		},payInvoice_grid]
	});
	function search(){
		var keyWords=payInvoice_formPanel.getForm().findField("keyWords").getValue();
		payInvoice_store.baseParams={searchConditions:keyWords};
		payInvoice_store.load();
	}
	/*获得操作栏htmlcode*/
	function getHtmlCode(value,metadata,record,rowIndex,store){
		var arr=[];
		var res="";
		arr.push("<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\""+win.id+"\").initialDetailView("+record.id+");'>操作</a>");
		if(record.data.status==0){
			arr.push("<a style='font-size:12px' href='javascript:Ext.CUR_APP.getModule(\""+win.id+"\").delPayInvoice("+record.id+");'>删除</a>");
		}
		Ext.each(arr,function(obj){
			res+=obj+" | ";
		});
		res=res.substring(0,res.length-3);
		return res;
	}
	
	return payInvoice_formPanel;
	},
	initEvent:function(){
		var module=this;
		var win=module.getObjByKey("win");
		win.on('show',function(){
			this.getObjByKey("store").load();
		},module,{single:true});
	},
   createWindow : function(params){
   	  var windowId=this.id;
   	  if(params){
   	  	windowId+="_"+params.winId;
   	  }
      var desktop = this.app.getDesktop();   
      var win = desktop.getWindow(windowId);
      if(!win){ 
      	var module=this;
         win = desktop.createWindow({
            id: windowId,
            width: 1000,
            height: 500,
            title:'付款单列表',
            iconCls: 'acc-icon',
            shim: false,
            moduleObj:this,
            constrainHeader: true,
            maximizable: true,
            layout: "fit", 
            items:[params=='undefined'?this.getPanel():this.getPanel(params)],
            listeners:{
            	'resize':function(win,width,height){
            		var top=this.items.get(0).items.first();
            		var grid=this.items.get(0).items.last();
            		var winMinWidth=1000;
            		var winMinHeight=440;
            		if(width<winMinWidth||height<winMinHeight){
            			win.setWidth(winMinWidth);
            			win.setHeight(winMinHeight);
            			grid.setHeight(winMinHeight-110);
            		}else{
            			grid.setHeight(height-110);
            			
            		}
            	
            	}
            }
         });
         module.objsCollection.add("win",win);
         module.initEvent();
      } 
      win.show();
   }
	});

